package com.ssh.manager.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.ssh.common.util.Page;
import com.ssh.dao.IDao;
import com.ssh.entity.Position;
import com.ssh.entity.SuperMarket;
import com.ssh.manager.PositionManager;

@Service
public class PositionManagerImpl implements PositionManager {
	@Resource
	private IDao daoImpl;

	@Override
	public Position getById(Long id) {
		return daoImpl.getDomain(Position.class, id);
	}
	
	@Override
	public Position saveUpdate(Position position) {
		return daoImpl.saveOrUpdateDomain(position);
	}

	@Override
	public void findListByPage(Page page, String isDesc) {
		String sql = "select count(*) from Position where del!=1";
		
		int sum = daoImpl.countAll(sql, null);
		page.setTotalCount(new Long(sum));
		page.countTotalPageNum();
		
		sql = "from Position where del!=1 order by createDate "+isDesc;
		List<Position> positions = (List<Position>)daoImpl.findListBySql(sql, new Object[]{}, false, true, false, page.getNumberPerPage()*(page.getCurPageNum()-1), page.getNumberPerPage());
		page.setPageData(positions);
	}

	@Override
	public List<Position> getAll() {
		String sql = "from Position where del!=1 order by createDate desc";
		List<Position> positions = (List<Position>)daoImpl.findListBySql(sql, new Object[]{}, false, true, false, 0, -1);
		return positions;
	}

	@Override
	public boolean verificationName(String name) {
		String sql = "from Position where del!=1 and name=?";
		List<Position> positions = (List<Position>)daoImpl.findListBySql(sql, new Object[]{name}, false, true, false, 0, -1);
		if(positions.size()>0){
			return true;
		}else{
			return false;
		}
	}
}
